package com.mmz.spring.aop.framework;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.aopalliance.intercept.Interceptor;
import org.aopalliance.intercept.MethodInterceptor;

import com.mmz.spring.aop.MethodBeforeAdvice;
import com.mmz.spring.aop.interceptor.MethodBeforeAdviceInterceptor;
import com.mmz.spring.aop.support.Advisor;


public class DefaultAdvisorChainFactory {
	
	public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
			Advised config, Method method, Class<?> targetClass) {

		
		List<Object> interceptorList = new ArrayList<Object>(config.getAdvisors().length);
		
		

		for (Advisor advisor : config.getAdvisors()) {
			// 用pointcut对拦截器做过滤
			if(advisor.getPointcut().getMethodMatcher().matches(method, targetClass)){
				if(advisor.getAdvice() instanceof MethodBeforeAdvice)
					interceptorList.add(new MethodBeforeAdviceInterceptor((MethodBeforeAdvice) advisor.getAdvice()));
				// ...还有别的aop advice，暂时先留着
			}

		}

		return interceptorList;
	}

}
